package com.cskaoyan.market.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.Serializable;

/**
 * @ClassName MarketSessionManager
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/3/28 15:43
 * @Version V1.0
 **/
@Component
public class MarketSessionManager extends DefaultWebSessionManager {

    public static final String WX_HEADER = "X-CskaoyanMarket-Token";

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        //获取这个请求头的值，作为session的编号
        String header = WebUtils.toHttp(request).getHeader(WX_HEADER);
        if(header != null){
            return header;
        }
        return super.getSessionId(request, response);
    }
}
